package org.mclll.xwangplugin.config.command;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.mclll.xwangplugin.MclllCustom;
import org.mclll.xwangplugin.config.GlobalConfig;

import java.util.Collections;
import java.util.List;

/**
 * @author llB
 * @date 2024-06-15 22:02
 * @description todo
 */
public class ReloadCommand implements TabExecutor {
    private MclllCustom mclllCustom;

    public ReloadCommand(MclllCustom mclllCustom) {
        this.mclllCustom = mclllCustom;
    }
    @Override
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
        if (!sender.isOp()) {
            return false;
        }
        sender.sendMessage("正在重载配置文件...");
        GlobalConfig.init(mclllCustom.getDataFolder());
        sender.sendMessage("正在重载完成");
        return true;
    }

    @Override
    public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
        return sender.isOp() ? Collections.singletonList("reload") : null;
    }
}
